<%@page language="java" contentType="text/html; charset=utf-8"%>
<%@include file="/commons/inc.jsp" %>

<h3 id="navTitleId">生存质量特异性量表</h3>

<script>
function show(){
	var a = '<s:property value='qualityResult.answer'/>';
	if(a!=null){
		a = a.split(",");
		for(var i=1;i<=a.length;i++){
			$('answer'+i+"-"+a[i-1].trim()).checked = true;
		}
	}
}
</script>
<body id="body">

<%@include file="/commons/showmessage.jsp" %>

<form name="qualityform" id="qualityform" method="post" action="${contextPath}/survey/survey.action?method=saveEditQualitySurvey">
	<s:hidden name="qualityResult.seqid" id="qualityResult.seqid"></s:hidden>
	<s:hidden name="qualityResult.patientid" id="qualityResult.patientid"></s:hidden>
	<s:hidden name="total" id="total"></s:hidden>
	<s:hidden name="totala" id="totala"></s:hidden>
	<s:hidden name="totalb" id="totalb"></s:hidden>
	<s:hidden name="totalc" id="totalc"></s:hidden>
	<s:hidden name="totald" id="totald"></s:hidden>
	<s:hidden name="answer" id="answer"></s:hidden>
	<s:hidden name="patientid" id="patientid"></s:hidden>
	
	<table  border="0" cellspacing="1" cellpadding="0" class="formTable" width="100%">
		<thead>
			<tr><td width="100%" align="left" class="form-th" colspan="7">糖尿病人生存质量特异性量表</td></tr>
		</thead>
		
	<tbody> 
		  <s:iterator value="qualitySurvey" id="ind" status="index">	
		  <s:if test="category.startsWith('G') && dimension==1"><tr><td align="left" class="form-td" colspan="7"><b>一、糖尿病对生理功能的影响</b></td></tr></s:if>
		  <s:if test="category.startsWith('G') && dimension==2"><tr><td align="left" class="form-td" colspan="7"><b>二、心理／精神维度</b></td></tr></s:if>
		  <s:if test="category.startsWith('G') && dimension==3"><tr><td align="left" class="form-td" colspan="7"><b>三、社会关系维度</b></td></tr></s:if>
		  <s:if test="number.startsWith('1') && dimension==4"><tr><td align="left" class="form-td" colspan="7"><b>四、治疗维度</b></td></tr></s:if>
		  	<tr>
		  		<td align="center" class="form-td" width="8%">${category}${number}</td>
				<td align="left" class="form-td" width="31%">${question}</td>
				<td align="left" class="form-td" width="11%"><input style="vertical-align:sub;"  type="radio" name="answer${seqid}" id="answer${seqid}-1" value="1"/><font style="vertical-align:sub;">${level1}</font></td>
				<td align="left" class="form-td" width="14%"><input  style="vertical-align:sub;" type="radio" name="answer${seqid}" id="answer${seqid}-2" value="2"/><font style="vertical-align:sub;">${level2}</font></td>
				<td align="left" class="form-td" width="14%"><input  style="vertical-align:sub;" type="radio" name="answer${seqid}" id="answer${seqid}-3" value="3"/><font style="vertical-align:sub;">${level3}</font></td>	
				<td align="left" class="form-td" width="11%"><input  style="vertical-align:sub;" type="radio" name="answer${seqid}" id="answer${seqid}-4" value="4"/><font style="vertical-align:sub;">${level4}</font></td>	
				<td align="left" class="form-td" width="11%"><input  style="vertical-align:sub;" type="radio" name="answer${seqid}" id="answer${seqid}-5" value="5"/><font style="vertical-align:sub;">${level5}</font></td>	
			</tr>
	 	</s:iterator><script>show()</script>
	 	 
	 		<tr>
	 			<td align="center" class="form-td">结果：</td>
	 			<td align="left" class="form-td" >总分：<s:property value='qualityResult.total'/></td>
	 			<td align="left" class="form-td" >生理功能：<s:property value='qualityResult.totala'/></td>
	 			<td align="left" class="form-td" >心理/精神维度：<s:property value='qualityResult.totalb'/></td>
	 			<td align="left" class="form-td" >社会关系维度：<s:property value='qualityResult.totalc'/></td>
	 			<td align="left" class="form-td" colspan="2" >治疗维度：<s:property value='qualityResult.totald'/></td>
	 		</tr>
		</tbody>
	</table>
	<table>
		<tr>
			<td align="center" colspan="5">
			<input type="reset"  value="重置">
		    <input type="button" onclick="saveEdit();" value="保存"></td>
		</tr>
	</table>
</form>

<%@include file="/commons/tableSel.jsp" %>

</body>

<style type="text/css">
body {
	height: 100%;
	width: 100%;
}
</style>

<script>
function saveEdit(){
	if(!Validator.Validate($('qualityform'),3)){
		return;
	}	
	var s = "";
	var a=0,b=0,c=0,d=0,total=0;
	<s:iterator value="qualitySurvey" id="ind" status="st">
		var category = '<s:property value='#ind.category'/>';
		var dimension = '<s:property value='#ind.dimension'/>';
		var i = '<s:property value='#st.index+1'/>';
		var r = document.getElementsByName("answer"+i);
		if(r!=null){
			var flag = false;
		 	for(var j=0;j<r.length;j++){
		 		if(r[j].checked){
		 			if(dimension=='1' && category=='F'){
		 				a+= parseInt(r[j].value);
		 			}else if(dimension=='2' && category=='F'){
		 				b+= parseInt(r[j].value);
		 			}else if(dimension=='3' && category=='F'){
		 				c+= parseInt(r[j].value);
		 			}else if(dimension=='4' && category=='F'){
		 				d+= parseInt(r[j].value);
		 			}
					s += r[j].value+",";
					flag = true;
				}
		 	}
		 	if(!flag){
			 	alert("请填写完整: 第"+category+"."+dimension+"题");
			 	return;
		 	}
		}
	 </s:iterator>
	 total = a+b+c+d;
	 if(s!=""){
		 s = s.substring(0,s.length-1);
	 }
	$('qualityform').answer.value = s;
	$('qualityform').total.value = total;
	$('qualityform').totala.value = a;
	$('qualityform').totalb.value = b;
	$('qualityform').totalc.value = c;
	$('qualityform').totald.value = d;
	$('qualityform').submit();
}
</script>